package buco.core.api;

public class RequireBundleRequirement extends Requirement {

	private String bundleSymbolicName;
	private VersionRange bundleVersionRange; 
	
	public RequireBundleRequirement(String bundleSymbolicName) {
		this.bundleSymbolicName = bundleSymbolicName; 
	}
	
	@Override
	public boolean isSatisfiedBy(Bundle bundle, Capability capability) {
		if(capability instanceof ExportPackageCapability) {
			if(this.bundleSymbolicName.equals(bundle.getBundleSymbolicName())) {
				// Are there versions?
				if(this.bundleVersionRange != null && bundle.getBundleVersion() != null){
					return this.bundleVersionRange.matchesVersion(bundle.getBundleVersion());
				}
				return true; 
			}
		}
		return false;
	}

	public VersionRange getBundleVersion() {
		return bundleVersionRange;
	}

	public void setBundleVersion(VersionRange bundleVersion) {
		this.bundleVersionRange = bundleVersion;
	}

	public String getBundleSymbolicName() {
		return bundleSymbolicName;
	}
	
	@Override
	public void accept(MetadataVisitor visitor) {
		visitor.visit(this);		
	} 

}
